import 'package:flutter/material.dart';
import 'package:flutter_comm_base_framework/core/dialog/dialog_loading.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'AppEnum.dart';
export "AppEnum.dart";

abstract class CommStatelessPage extends StatelessWidget {

  //延时默认500毫秒调用initPageData()
  int delayedInitPageDataFunc = 100;

  DialogLoading loadingDialog;
  BuildContext context;

  CommStatelessPage(this.context);

  CommStatelessWidget(){

    initBaseParams();

    Future.delayed(Duration(microseconds: delayedInitPageDataFunc), () {
      initPageData();
    });
    // 进入页面统计
    String pageName = "${this.runtimeType.toString()}";
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return KeyboardDismisser(
        gestures: [GestureType.onTap, GestureType.onPanUpdateDownDirection],
        child: getViewsWidget()
    );
  }




  @override
  void dispose() {
    // TODO: implement dispose
// 离开页面统计
    String pageName = "${this.runtimeType.toString()}";
  }

  @override
  void showProgressDialog({String msg, bool canCancel = true}){
    if(loadingDialog == null){
      loadingDialog = DialogLoading(context);
    }
    loadingDialog.showLoading(msg: msg);
  }

  @override
  void showToastTip(String tips) {
    Fluttertoast.showToast(
        msg: tips,
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.black54,
        textColor: Colors.white,
        fontSize: 16.0);
  }

  @override
  void hideProgressDialog(){
    if(loadingDialog != null){
      loadingDialog.hideLoading();
      loadingDialog = null;
    }
  }

  @override
  BuildContext getContext() {
    return context;
  }


  void hideKeyboard(){
    FocusScope.of(context).requestFocus(FocusNode());
  }

  //初始化页面基本参数
  void initBaseParams();

  //初始化页面数据
  void initPageData();

  //页面Views组件
  Widget getViewsWidget();

  //调用接口数据
  void queryServiceData({ServiceType type = ServiceType.Default,bool showAnimail = true}) async{

  }

  Object getPageArguments(){
    return ModalRoute.of(context).settings.arguments;
  }
}
